# -*- coding: utf-8 -*-
import os
import sys

import tablib

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "base.settings")

from common.transaction import db as transaction_db
from common.utils.export import gen_filename

query_dct = {
    'status': 2,
    'updated_at': '{"$gte": "2018-03-31 16:00:00", "$lte": "2018-04-30 16:00:00"}'
}

filename = gen_filename('withdraw_records')
header = [
    u'提现单号', u'用户ID', u'提现金额', u'实际金额', u'提现方式',
    u'提现通道', u'提现时间', u'提现状态', u'更新时间', u'姓名',
    u'联系方式', u'账户信息1', u'账户信息2', u'第三方流水号', u'交易时间']
items = transaction_db.export_withdraw_records(query_dct)

data = tablib.Dataset(*items, headers=header)

with open('/tmp/' + filename, 'wb') as f:
    f.write(data.xlsx)
